#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

using namespace cv; //Must Need Write cv
using namespace std;

/*
 * ./opencv_imwrite <image_path1>
 *
 */

int main(int argc, char** argv)
{
    if (argc < 2) {
        std::cerr << "Usage: " << argv[0] << " <image_path1>  " << std::endl;
        return -1;
    }
    
    Mat img4 = imread(argv[1], IMREAD_COLOR);

    std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 40};
    
    imwrite("/userdata/quality_test_demo_40.jpg", img4, params);

    params = {cv::IMWRITE_JPEG_QUALITY, 100};
    imwrite("/userdata/quality_test_demo_100.jpg", img4, params);
    
    // 创建一个空的 vector 容器
    std::vector<int> myVector;

    // 向 vector 容器尾部添加元素
    myVector.push_back(3);
    myVector.push_back(7);
    myVector.push_back(12);

    // 使用迭代器遍历 vector 容器并输出其中的元素
    // 在 C++ 中，auto 是一个关键字，用于声明变量时的类型推断。
    // 它允许编译器根据变量的初始化表达式推断出变量的类型，从而简化代码书写过程。
    std::cout << "Vector elements: ";
    for (auto it = myVector.begin(); it != myVector.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;

    // 获取 vector 容器的大小和访问特定位置的元素
    std::cout << "Vector size: " << myVector.size() << std::endl;
    std::cout << "Element at index 1: " << myVector[1] << std::endl;

    // 修改特定位置的元素
    myVector[2] = 20;

    // 使用范围-based for 循环遍历 vector 并输出元素
    std::cout << "Modified Vector elements: ";
    for (int num : myVector) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    // 清空 vector 容器
    myVector.clear();

    // 检查 vector 是否为空
    if (myVector.empty()) {
        std::cout << "Vector is empty." << std::endl;
    } else {
        std::cout << "Vector is not empty." << std::endl;
    }
    
    return 0;
}


